/*
 * Android Runner is a multiplayer GPS game fully written by Xurxo Mendez Perez
 * 
 * Copyright (C) 2009 Xurxo Mendez Perez
 *   
 * This file is part of Android Runner.
 * 
 * Android Runner is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Android Runner is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Android Runner.  If not, see <http://www.gnu.org/licenses/>.
 */

package es.sonxurxo.androidrunner.model.persistence.item.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.PrimaryKeyJoinColumn;

import es.sonxurxo.androidrunner.model.persistence.game.entity.Game;


/**
 * 
 * @author "Xurxo Mendez Perez"
 *
 */
@Entity
@PrimaryKeyJoinColumn
@DiscriminatorValue("QUE")
public class Question extends Item implements Serializable {

	private static final long serialVersionUID = 2585137052816483062L;
	private QuestionData questionData;
	private Set<Bonus> bonuses = new HashSet<Bonus>();
	
	public Question() {
		this.questionData = new QuestionData();
		// Empty on purpose
	}
	
	public Question(Game game, int latitude, int longitude, 
			String question, String option1, String option2, String option3, int answer) {
		super(game, latitude, longitude);
		this.questionData = new QuestionData(question, option1, option2, option3, answer);
	}

	@OneToMany(mappedBy = "question", fetch = FetchType.LAZY)
	public Set<Bonus> getBonuses() {
		return this.bonuses;
	}

	public void setBonuses(Set<Bonus> bonuses) {
		this.bonuses = bonuses;
	}
	
	public void addBonus(Bonus bonus) {
		this.bonuses.add(bonus);
		bonus.setQuestion(this);
	}
	
	public void removeBonus(Bonus bonus) {
		this.bonuses.remove(bonus);
		bonus.setQuestion(null);
	}

	@ManyToOne
	@JoinColumn(name = "questionDataId")
	public QuestionData getQuestionData() {
		return this.questionData;
	}

	public void setQuestionData(QuestionData questionData) {
		this.questionData = questionData;
	}
	
}
